home *** CD-ROM | disk | FTP | other *** search
/ APDL Other Worlds / APDL Other Worlds Collection.iso / SF3000 / Extras / !SFskyedit / c / DCS_dialogue < prev    next >
Encoding:
Text File  |  2003-10-16  |  3.6 KB  |  101 lines

  1. /*
  2.  *  SFskyedit - Star Fighter 3000 sky colours editor
  3.  *  DCS dialogue
  4.  *  Copyright (C) 2001  Chris Bazley
  5.  *
  6.  *  This program is free software; you can redistribute it and/or modify
  7.  *  it under the terms of the GNU General Public Licence as published by
  8.  *  the Free Software Foundation; either version 2 of the Licence, or
  9.  *  (at your option) any later version.
  10.  *
  11.  *  This program is distributed in the hope that it will be useful,
  12.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  *  GNU General Public Licence for more details.
  15.  *
  16.  *  You should have received a copy of the GNU General Public Licence
  17.  *  along with this program; if not, write to the Free Software
  18.  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  */
  20.  
  21. /* ANSI library files */
  22. #include <string.h>
  23. #include <stdbool.h>
  24.  
  25. /* RISC OS library files */
  26. #include "toolbox.h"
  27. #include "event.h"
  28. #include "dcs.h"
  29.  
  30. /* My library files */
  31. #include "Macros.h"
  32. #include "err.h"
  33. #include "FilePerc.h"
  34. #include "InputFocus.h"
  35.  
  36. /* Local headers */
  37. #include "EditSky.h"
  38. #include "DCS_dialogue.h"
  39. #include "SFSSaveBox.h"
  40. #include "Utils.h"
  41.  
  42. ObjectId dcs_sharedid = NULL_ObjectId;
  43. bool dcs_openparent = false;
  44.  
  45. /* ----------------------------------------------------------------------- */
  46. /*                       Function prototypes                               */
  47.  
  48. static ToolboxEventHandler _DCS_actions_handler;
  49.  
  50. /* ----------------------------------------------------------------------- */
  51. /*                         Public functions                                */
  52.  
  53. void DCS_initialise(ObjectId dcs_id)
  54. {
  55.   /* Record ID */
  56.   dcs_sharedid = dcs_id;
  57.  
  58.   /* Install handlers */
  59.   EF(event_register_toolbox_handler(dcs_id, -1, _DCS_actions_handler, NULL));
  60.   EF(event_register_toolbox_handler(dcs_id, DCS_AboutToBeShown, InputFocus_recordcaretpos, NULL));
  61. }
  62.  
  63. /* ----------------------------------------------------------------------- */
  64. /*                         Private functions                               */
  65.  
  66. static int _DCS_actions_handler(int event_code, ToolboxEvent *event, IdBlock *id_block, void *handle)
  67. {
  68.   ViewData *view_data;
  69.   if(toolbox_get_client_handle(0, id_block->ancestor_id, (void **)&view_data) != NULL)
  70.     return 0; /* Main window has probably been deleted already */
  71.  
  72.   switch(event_code) {
  73.     case DCS_Save:
  74.       if(strchr(view_data->last_savepath, (int)'.') == NULL) {
  75.         /* Must open savebox first */
  76.         RE(open_topleftofwin(Toolbox_ShowObject_AsMenu, savebox_sharedid, id_block->ancestor_id, id_block->self_id, id_block->self_component))
  77.         /* N.B. The savebox won't open immediately (until SaveAs_AboutToBeShown has been delivered). This gives us a chance to restore the caret to the main window and thus preserve the backwards link */
  78.         return 1; /* claim event */
  79.       }
  80.       /* Save immediately */
  81.       {
  82.         _kernel_oserror *err = perc_operation(FILEPERC_OP_COMP, view_data->last_savepath, FILETYPE_SKYCOLS, (flex_ptr)&view_data->sky);
  83.         if(err != NULL) {
  84.           /* Saving error */
  85.           err_report(err->errnum, msgs_lookup_sub1("SaveFail", err->errmess));
  86.           return 1; /* claim event */
  87.         }
  88.       }
  89.       /* After successful save, carry straight on as for Discard... */
  90.  
  91.     case DCS_Discard:
  92.       if(dcs_openparent)
  93.         EditSky_openparentdir(view_data); /* Open parent directory */
  94.  
  95.       /* the EditSky object's handlers will do the rest... */
  96.       RE(toolbox_delete_object(0, id_block->ancestor_id))
  97.       return 1; /* claim event */
  98.   }
  99.   return 0; /* He's not the messiah, he's a very naughty boy! */
  100. }
  101.